<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib/axios.js"></script>
    <link rel="stylesheet" href="./lib/bootstrap.css">
    <script src="./lib/jquery.js"></script>
</head>

<body>
    <button id="btn1">发起GET请求</button>
    <button id="btn2">发起POST请求</button>
    <button id="btn3">直接使用axios发起GET请求</button>
    <button id="btn4">直接使用axios发起POST请求</button>
    <br> axios发起get请求的基本语法：axios.get('url', { params: ( /*参数*/ ) } ).then(callback)
    <br> axios发起post请求的基本语法：axios.post('url',{ /*参数*/ } ).then(callback)
    <script>
        document.querySelector('#btn1').addEventListener('click', function() {
            var url = 'http://www.liulongbin.top:3006/api/get'
            var paramsObj = {
                name: 'zs',
                age: 20
            }
            axios.get(url, {
                params: paramsObj
            }).then(function(res) {
                console.log(res) //包装后的数据
                console.log(res.data) //服务器返回的原始数据
            })
        });

        document.querySelector('#btn2').addEventListener('click', function() {
            var url = 'http://www.liulongbin.top:3006/api/post'
            var dataObj = {
                address: '北京',
                location: '顺义区'
            }
            axios.post(url, dataObj).then(function(res) {
                console.log(res);
                console.log(res.data);
            })
        });



        document.querySelector('#btn3').addEventListener('click', function() {
            var url = 'http://www.liulongbin.top:3006/api/get'
            var paramsData = {
                name: '钢铁侠',
                age: 35
            }
            axios({
                method: 'GET',
                url: url,
                params: paramsData
            }).then(function(res) {
                console.log(res);
                console.log(res.data)
            })
        });


        document.querySelector('#btn4').addEventListener('click', function() {
            axios({
                method: 'POST',
                url: 'http://www.liulongbin.top:3006/api/post',
                data: {
                    name: '娃哈哈',
                    age: 18,
                    gender: '女'
                }
            }).then(function(res) {
                console.log(res);
                console.log(res.data);
            })
        });
    </script>
</body>

</html>